#include <iostream>
#include <string>
#include <vector>
#include <fstream>

#include "Mx.h"
#include "Mc.h"



using namespace std;

int main()
{
    vector<string> TR;
    int NTR ;
    vector<string> VT;
    int NVT;
    vector<string> CARSPE;
    vector<int> C;
    vector<bool> B;
    vector<vector<int> > CODE, NUM, TACHE;
    int ERR = 0;
    int NBUFFIN;
    string ligne;
    string mot_attendu;
    string mot_trouve;
    string BUFFIN;
    bool b = false;

    vector<vector<int> > A, PA, O, PO;
    int NA, NPA, NO, NPO;



    ifstream lecflux;   //Un flux permettant de lire un fichier

    NTR = 5;
    //lecture de BNF
    lecflux.open("BNF.txt"); //Ouverture du fichier

    if(lecflux)
    {
        for (int i=0; i<NTR; ++i)
        {
            getline(lecflux, ligne);
            TR.push_back(ligne);
        }
    }

    lecflux.close();

    //lecture de CARSPE
    lecflux.open("CARSPE.txt");

    if(lecflux)
    {
        for (int i=0; i<12; ++i)
        {
            getline(lecflux, ligne);
            CARSPE.push_back(ligne);
        }
    }

    lecflux.close();


    M0(TR, NTR, VT, NVT, CARSPE, C, CODE, NUM, TACHE, ERR);


    M1(CODE, NUM, TACHE, C, B, NTR, ERR);


    M2(CODE, NUM, TACHE, C, B, NTR, PA, NPA, A, NA, PO, NPO, O, NO);

/*
    cout<<"matrice A"<<endl;
    for(int i=0 ; i<NA ; ++i)
    {
        cout<<A[i][0]<<" "<<A[i][1]<<endl;
    }

    cout<<"matrice O"<<endl;
    for(int i=0 ; i<NO ; ++i)
    {
        cout<<O[i][0]<<" "<<O[i][1]<<endl;
    }

    cout<<"matrice PA"<<endl;
    for(int i=0 ; i<NPA ; ++i)
    {
        cout<<PA[i][0]<<" "<<PA[i][1]<<endl;
    }

    cout<<"matrice PO"<<endl;
    for(int i=0 ; i<NPO ; ++i)
    {
        cout<<PO[i][0]<<" "<<PO[i][1]<<endl;
    }

    cout<<"matrice CODE"<<endl;
    for(int i=0 ; i<NTR ; ++i)
    {
        for(int j=0 ; j<C[i] ; ++j)
        {
            cout<<CODE[i][j]<<" ";
        }
        cout<<endl;
    }

    cout<<"matrice NUM"<<endl;
    for(int i=0 ; i<NTR ; ++i)
    {
        for(int j=0 ; j<C[i] ; ++j)
        {
            cout<<NUM[i][j]<<" ";
        }
        cout<<endl;
    }

    cout<<"matrice TACHE"<<endl;
    for(int i=0 ; i<NTR ; ++i)
    {
        for(int j=0 ; j<C[i] ; ++j)
        {
            cout<<TACHE[i][j]<<" ";
        }
        cout<<endl;
    }
//*/

    ERR=0;
    mot_attendu="create";
    BUFFIN="create bielle meule artichaud";
    NBUFFIN=BUFFIN.size();
    recup(b, mot_attendu, ERR, NBUFFIN, BUFFIN, mot_trouve);

    return 0;
}
